package practice;

import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class _05IndexH {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int L = scanner.nextInt();
        Integer[] nums = new Integer[N];
        for (int i = 0;i < N;i++){
            nums[i] = scanner.nextInt();
        }
        scanner.close();
        Arrays.sort(nums, Collections.reverseOrder());

        //  枚举法
        int h = 0;
        for (int i = 0,j = N-1;i < N;i++){
            while (j >= 0 && nums[j] < i+1){
                //  从右往左寻找第一个 nums[j] >= i+1
                //  注意 i 越大，满足条件的 j 越小
                j--;
            }
            if (nums[i] >= i && i-j <= L){
                //  表示原本nums[i]就满足条件或者说增补1后可满足条件
                //
                h = i+1;
            }
        }
        System.out.println(h);
    }
}
